﻿//<my-matriculator - a simple tool for registering racers in a USAC cyclocross race>
//Copyright (C) <2011>  <Steven Rivers>

//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System.ComponentModel;

namespace Registration.Model.Entities
{
    public class Category : INotifyPropertyChanged
    {
        private int _categoryid;
        public int CategoryId
        {
            get { return _categoryid; }
            set
            {
                _categoryid = value;
                OnPropertyChanged(new PropertyChangedEventArgs("CategoryID"));
            }
        }

        private string _categoryname;
        public string CategoryName
        {
            get { return _categoryname; }
            set
            {
                _categoryname = value;
                OnPropertyChanged(new PropertyChangedEventArgs("CategoryName"));
            }
        }

        private int _categoryfield;
        public int CategoryField
        {
            get { return _categoryfield; }
            set
            {
                _categoryfield = value;
                OnPropertyChanged(new PropertyChangedEventArgs("CategoryField"));
            }
        }
       
        public event PropertyChangedEventHandler PropertyChanged;
        
        public void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, e);
        }
        
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (Category)) return false;
            return Equals((Category) obj);
        }

        public Category(int id, string name, int field)
        {
            CategoryId = id;
            CategoryName = name;
            CategoryField = field;
        }

        public bool Equals(Category other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other._categoryid == _categoryid && Equals(other._categoryname, _categoryname) && other._categoryfield == _categoryfield;
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = _categoryid;
                result = (result*397) ^ (_categoryname != null ? _categoryname.GetHashCode() : 0);
                result = (result*397) ^ _categoryfield;
                return result;
            }
        }
    }

}